package code.ws_common_utils
{
	import flash.utils.IDataInput;
	import flash.utils.IDataOutput;
	
	public class Long
	{
		private var _high:int=0;
		private var _low:uint=0;

		public function Long(value:Number=0)
		{
			if (value != 0)
			{
				this._high=int(value / 0x100000000);
				this._low=uint(value & 0xFFFFFFFF);
			}  
		}

		public static function readFrom(source:IDataInput):Long
		{
			var n:Long=new Long();
			n._high=source.readInt();
			n._low=source.readUnsignedInt();
			return n;
		}

		public function setValue(high:int, low:uint):void
		{
			this._high=high;
			this._low=low;
		}

		public function writeTo(target:IDataOutput):void
		{
			target.writeInt(_high);
			target.writeUnsignedInt(_low);
		}

		public function get high():int
		{
			return _high;
		}

		public function get low():uint
		{
			return _low;
		}

		public function uintValue():uint
		{
			return _low;
		}

		public function valueOf():Number
		{
			return (_high * 0x100000000) + _low;
		}

		public function toString():String
		{
//                return valueOf().toString();
			if (high == 0)
			{
				return low.toString();
			}
			return high.toString() + low.toString();
		}

		public function euqals(l:Long):Boolean
		{
			return this.low == l.low && this.high == l.high
		}

		/**
		 *大返回1，小返回-1，等于返回0
		 * @param l
		 * @return
		 *
		 */
		public function moreOrLessLong(l:Long):int
		{
			if (euqals(l))
			{
				return 0;
			}
			if (this.high > l.high)
			{
				return 1
			}
			if (this.high < l.high)
			{
				return -1
			}
			if (this.low > l.low)
			{
				return 1
			}
			if (this.low < l.low)
			{
				return -1
			}

			return 0
		}

		/**
		 *大返回1，小返回-1，等于返回0
		 * @param l
		 * @return
		 *
		 */
		public function moreOrLessInt(l:int):int
		{
			var long:Long=new Long()
			long.setValue(0,l);

			return moreOrLessLong(long)
		}


	}
}